package day07;

public class quicksort {

	public static void swap(int[] arr,int i,int j){
		if(arr[i]==arr[j])return;
		arr[i]^=arr[j];
		arr[j]^=arr[i];
		arr[i]^=arr[j];
	}
	
	public static void quicksort(int arr[],int l,int r){
		if (l>=r) return; 
		int left = l,right= r;
		while (left < right) {
			if (arr[right]>=arr[l]){
				--right;
				continue;
				}
			else if (arr[left]<=arr[l]){
				++left;
				continue;
			}
			swap(arr,left,right);
			--right;
		}
		swap(arr,l,left);
		quicksort(arr,l,left-1);
		quicksort(arr,left+1,r);
	}
	
	public static void main(String[] args) {
		int[] arr = new int[]{12,-2,5,123,62,36,-52,0};
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i]+",");
		}
		quicksort(arr,0,arr.length-1);
		System.out.println();
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i]+",");
		}
		
	}

}
